package com.yuanfeng.commoms.util;

import com.yuanfeng.commoms.config.YFConfig;
import com.yuanfeng.commoms.exception.BizCodeEnume;

/**
 * @author Stranger
 * @date 2023/3/31 15:10
 */
public class TokenUtils {


    /**
     * 验证token是否为空
     * @param token
     * @return
     */
    public static ResponseResult checkToken(String token) {
        if (null != token && !"".equals(token)) {
            boolean isExist = RedisUtil.exists(YFConfig.YF_USER_TOKEN_USER  + token);
            if (isExist) {
                String userId = RedisUtil.get(YFConfig.YF_USER_TOKEN_USERID + token);
                if (null != userId) {
                    return ResponseResult.success(userId);
                }
            }
            return ResponseResult.fail(BizCodeEnume.TOKEN_IS_INVALID.getMsg());
        }
        return ResponseResult.fail(BizCodeEnume.TOKEN_IS_NULL.getMsg());

    }
}
